package com.example.learn_gl_android.anglib.util.math

data class Vector2 (val elements: FloatArray = FloatArray(2)){

    companion object {
        fun one() : Vector2 {
            val ret = Vector2()
            ret.elements[0] = 1f
            ret.elements[1] = 1f


            return ret
        }

        fun cross(v1: Vector2, v2 : Vector2) : Float{
            val ret = Vector2()
            val a = v1.elements
            val b = v2.elements

            return a[0] * b[1] - b[1] * a[0]
        }

        fun dot(v1: Vector3, v2 : Vector3) : Float{
            val a = v1.elements
            val b = v2.elements

            return a[0] * b[0] + a[1] * b[1]
        }
    }

    operator fun plus (other : Vector2) : Vector2{

        val ret = Vector2()
        ret.elements[0] = elements[0] + other.elements[0]
        ret.elements[1] = elements[1] + other.elements[1]

        return ret
    }
    operator fun plusAssign (other : Vector2) {
        elements[0] = elements[0] + other.elements[0]
        elements[1] = elements[1] + other.elements[1]

    }

    operator fun minus (other : Vector2) : Vector2{
        val ret = Vector2()
        ret.elements[0] = elements[0] - other.elements[0]
        ret.elements[1] = elements[1] - other.elements[1]

        return ret
    }

    operator fun minusAssign (other : Vector2) {
        elements[0] = elements[0] - other.elements[0]
        elements[1] = elements[1] - other.elements[1]

    }




    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as Vector2

        return elements.contentEquals(other.elements)
    }

    override fun hashCode(): Int {
        return elements.contentHashCode()
    }
}